import 'package:flutter/cupertino.dart';
import 'package:meePet/utils/ScreenUtils.dart';
import 'package:meePet/utils/ext/SizeExt.dart';
import 'package:meePet/utils/ext/StringExt.dart';

import '../../../app/LocalColor.dart';
import '../../../app/RouteConstants.dart';
import '../../../bean/msg/MsgData.dart';
import '../../../manager/RouteManager.dart';

class ConversationItem {
  Widget getMsgItem(ConversationMsg msg) {
    Widget temp;
    switch (msg.type) {
      case 1:
        temp = _getP2PItem(msg);
        break;
      default:
        temp = _getP2PItem(msg);
        break;
    }
    return temp;
  }

  Widget _getGroupItem(ConversationMsg msg) {
    return GestureDetector(
      onTap: () {
        _jumpChat(msg);
      },
      child: Container(
          width: 335.sw(),
          height: 60.sw(),
          decoration: const BoxDecoration(
            color: LocalColor.colorWhite,
          ),
          child: Stack(alignment: Alignment.topLeft, children: [
            Container(
              padding: EdgeInsets.all(15.sw()),
              child: "icon_phone".png().loadImageRes(35.sw(), 35.sw()),
            ),
            Text(
              msg.nickname.orEmpty(),
              style: TextStyle(
                color: LocalColor.color_FF89888D,
                fontSize: 11.sp(),
              ),
            ),
          ])),
    );
  }

  Widget _getP2PItem(ConversationMsg msg) {
    return GestureDetector(
      onTap: () {
        _jumpChat(msg);
      },
      child: Container(
          width: ScreenUtils.screenWidth/3,
          height: 60.sw(),
          decoration: const BoxDecoration(
            color: LocalColor.colorWhite,
          ),
          child: Stack(alignment: Alignment.topLeft, children: [
            Container(
              margin: EdgeInsets.all(15.sw()),
              child: "icon_phone".png().loadImageRes(50.sw(), 50.sw()),
            ),
            Container(
              margin: EdgeInsets.only(left: 100.sw(),top: 5.sw()),
              child: Text(
                msg.nickname.orEmpty(),
                style: TextStyle(
                  color: LocalColor.color_FF89888D,
                  fontSize: 11.sp(),
                ),
              ),
            ),
          ])),
    );
  }

  void _jumpChat(ConversationMsg msg) {
    RouteManager.to(RouteConstants.chatPage);
  }
}
